package com.swp.oa.comomn;

import java.io.File;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class MySQLDatabaseBackUpOption {

	private static String isStartBackUp ;
	
	private static String binPath = "";
	
	private static String userName = "";
	
	private static String passWord = "";
	
	private static String databaseName = "";
	
	private static String hostIP = "";
	
	private static String savePath = "";
	
//	private static String BackUpHour = "0";
//	
//	private static String BackUpMinute = "0";
//	
//	private static String BackUpSecond = "0";
	
	// 加载配置文件
	static {
		String path = Option.getConfigPath();
		loadConfigFile(path);
	}
	
	public static boolean getIsStartBackUp() {
//		Boolean.parseBoolean()
		if(isStartBackUp.equals("true")){
			return true;
		}
		return false;
	}

	public static String getBinPath() {
		return binPath;
	}

	public static String getUserName() {
		return userName;
	}

	public static String getPassWord() {
		return passWord;
	}

	public static String getDatabaseName() {
		return databaseName;
	}

	public static String getHostIP() {
		return hostIP;
	}

	public static String getSavePath() {
		return savePath;
	}

//	public static int getBackUpHour() {
//		return Integer.parseInt(BackUpHour);
//	}
//
//	public static int getBackUpMinute() {
//		return Integer.parseInt(BackUpMinute);
//	}
//
//	public static int getBackUpSecond() {
//		return Integer.parseInt(BackUpSecond);
//	}

	private static void loadConfigFile(String path) {
		SAXReader saxReader = new SAXReader();
		
		File file = new File(path);  //打开文件

		Document doc = null;
		try {
			//读取配置文件构造dom
			doc = saxReader.read(file);  
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		//获取根节点
		Element mySQLRoot = doc.getRootElement().element("MySQLDatabaseBackUp");
		
		//获取是否启动MySQL备份
		isStartBackUp = mySQLRoot.element("isStartBackUp").getText();
		//获取MySQL安装bin目录
		binPath = mySQLRoot.element("MySQ").element("binPath").getText();
		//获取MySQL配置参数
		userName = mySQLRoot.element("MySQ").element("userName").getText();
		passWord = mySQLRoot.element("MySQ").element("passWord").getText();
		databaseName = mySQLRoot.element("MySQ").element("databaseName").getText();
		hostIP = mySQLRoot.element("MySQ").element("hostIP").getText();
		//获取保存参数
		savePath = mySQLRoot.element("Path").getText();
		//获取备份时间
//		BackUpHour = mySQLRoot.element("Date").element("Hour").getText();
//		BackUpMinute = mySQLRoot.element("Date").element("Minute").getText();
//		BackUpSecond = mySQLRoot.element("Date").element("Second").getText();
		
	}
}
